'use strict';

exports.destroy = async ctx => {
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.feedback.destroy());
};

exports.update = async ctx => {
  ctx.validate({
    isShow: {
      type: 'boolean',
    },
  });
  ctx.validate({
    id: {
      type: 'mongo-id',
    },
  }, ctx.params);
  ctx.sendSuccess(await ctx.service.feedback.update());
};

exports.index = async ctx => {
  ctx.w_validate_page();
  const data = await Promise.all([ ctx.service.feedback.list(true), ctx.service.feedback.count(true) ]);
  const resData = {
    list: data[0],
    total: data[1],
    pageSize: ctx.query.pageSize,
    pageNum: ctx.query.pageNum,
  };
  ctx.sendSuccess(resData);
};

